<?php
/**
 * 微信二维码模型
 * @Author: phpzhi <phpzhi@qq.com><https://www.phpzhi.com>
 * @Date: 2019/11/7 14:07
 */

namespace app\common\model\wechat;


use think\Model;

class WechatQrcode extends Model
{
    protected $name = 'wechat_qrcode';

    public static function getWechatQrcodeCount($id = 0)
    {
        if (!$id) return 0;
        return self::where(['id' => $id])->count();
    }

    /**
     * 获取小程序二维码信息
     * @param int $id
     * @param string $field
     * @return array|bool|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getWechatQrcodeById($id = 0, $field = 'third_type,third_id,page')
    {
        if (!$id) return false;
        $count = self::getWechatQrcodeCount($id);
        if (!$count) return false;
        return self::where(['id' => $id])->where(['status' => 1])->field($field)->find();
    }
}